#!/bin/bash
#
set -e

USAGE="Usage: $0 -i package_name"

while getopts ir: OPT
  do case "$OPT" in
    i) echo "Searching package [$2]...";
      roslocate info $2 > /tmp/$2.rosinstall;
      echo "Package [$2] found.";      
      echo "Installing package [$2]...";
      rosinstall ~/ros /tmp/$2.rosinstall;
      echo "Package [$2] installed.";
      rm /tmp/$2.rosinstall;
      echo "Updating [~/ros/setup.bash]...";
      source ~/ros/setup.bash;
      echo "Done.";
      exit 0;
      ;;
    h) echo $USAGE
      exit 1;
      ;;
    \?) echo $USAGE
      exit 1;
      ;;
  esac
done
exit 0;
